2 Problem: 11481 - Arrange the Numbers
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Algorithm: Inclusion-exclusion principle
31 const int N
= 1000, mod
= 1000000007;
33 long long choose
[N
+1][N
+1], fact
[N
+1];
37 fact
[0] = fact
[1] = 1;
38 for (int i
=2; i
<=N
; ++i
) fact
[i
] = (fact
[i
-1]*i
)%mod
;
40 /* Binomial coefficients */
41 for (int i
=0; i
<=N
; ++i
) choose
[i
][0] = choose
[i
][i
] = 1;
42 for (int i
=1; i
<=N
; ++i
)
43 for (int j
=1; j
<i
; ++j
)
44 choose
[i
][j
] = (choose
[i
-1][j
-1] + choose
[i
-1][j
])%mod
;
54 scanf("%d %d %d", &n
, &m
, &k
);
57 for (int i
=0; i
<=m
-k
; ++i
){
58 ans
+= (i
& 1 ? -1 : 1) * (choose
[m
-k
][i
] * fact
[n
-k
-i
]) % mod
;
62 ans
= ((ans
* choose
[m
][k
]) % mod
+ mod
) % mod
;
64 printf("Case %d: %lld\n", pizza
++, ans
);